The qfloat data type

 

This floating-point library features numbers with 104 digits precision. It is based on the CEPHES mathematical Library written by Stephen L Moshier. It offers all standard mathematical functions and many others.

 

At a glance:

 

 

Overview

The essential functions are provided with the DLL and described below. The static library has many other functions, not included in the DLL distribution.

 

Qfloats are identical to other floating point data and no special constructs should be required. They can be initialized like this:

qfloat a = 0.88877766566544433322333443334434;

or

qfloat a = "0.88877766566544433322333443334434";

 

They can be freely mixed with other numerical data. The compiler will provide the necessary conversions.

 

Printing qfloats with xprintf.

 

You can use xprintf to print qfloats using the 'q' qualifier.

 

Example:

     qfloat data;

    

     xprintf("%40.30qf\n",data);

 

Qfloat functions

 

 

Function

Description

Constructors

qfloat qfloat(char *);

From ascii string

qfloat qfloat(int);

From integer

qfloat qfloat(double);

From double precision double

qfloat qfloat(long double);

From long double

void e24toq(const float *,qfloat *);

Converts a single precision float into a qfloat number.

void etoq(const double *,qfloat *);

Converts a double precision number into a qfloat

void e64toq(const double *,qfloat *);

Converts a long double number (80 bits) into a qfloat.

void ltoq(long *,qfloat *);

Converts a 32 bit integer in a qfloat.

void lltoq(long long *,qfloat *);

Converts a long long number into a qfloat.

void asctoq(const char *,qfloat *);

Converts a character string in a qfloat.

Output conversions

int qtoi(qfloat &);

Converts a qfloat into a 32 bit integer.

float qtof(qfloat &);

Converts a qfloat into a 32 bit float.

double qtod(qfloat &);

Converts a qfloat into a 64 bit double.

long double qtold(qfloat &);

Converts a qfloat into a 80 bit long double.

Operators

Only one version of the operator is presented, but normally all conversions from and to other numbers should be supported. See the header file for details. Both operators and normal functions are provided.

qfloat &operator +=(qfloat &x, const qfloat & y);

+= operator

qfloat operator +(const qfloat &x, const qfloat & y);

+ operator

void qadd(const qfloat &x, const qfloat &y, qfloat &z);

z = x + y

qfloat operator-(qfloat &x,qfloat &y);

- operator

void qsub(const qfloat &x,const qfloat &y,qfloat &z);

z = x - y

qfloat operator*(const qfloat &x,const qfloat &y);

* operator

void qmul(const qfloat &x,const qfloat &y,qfloat &z);

z = x*y

qfloat operator /(const qfloat & x, const qfloat & y);

/ operator

void qdiv(const qfloat &x,const qfloat &y,qfloat &z);

z = x/y

int operator==(qfloat &x,qfloat &y);

 

int operator!=(qfloat &x,qfloat &y);

 

int operator<(qfloat &x,qfloat &y);

 

int operator<=(qfloat &x,qfloat &y);

 

int operator==(qfloat &x,qfloat &y);

 

int operator>=(qfloat &x,qfloat &y);

 

int qcmp(qfloat &x,qfloat &y);

Compares two qfloats and returns zero for equality, 1 when x > y and –1 when z is less than y.

 

 

Utility functions

void qclear(qfloat *);

Zeroes a qfloat number.

Library functions

qfloat qsin(qfloat &);

Sin

qfloat qcos(qfloat &);

Cos

qfloat qtan(qfloat &);

Tan

qfloat qremain(const qfloat &x,const qfloat &y,qfloat &z);

Remainder. Result in Z.

qfloat qpow(qfloat &x,qfloat &y);

xy

qfloat qexp(qfloat &x);

ex

qfloat qexp10(qfloat *x, qfloat *y);

Returns 10 raised to the xth power

qfloat qlog(qfloat &x);

log(x)

qfloat qfloor(qfloat &x);

Largest integer not greater than x

qfloat qabs(qfloat &);

Absolute value

qfloat qsqrt(qfloat &);

Square root

qfloat mtherr(char *,int);

Error handling function.

qfloat qratio(int x,int y);

Builds a ratio of x/y without losing any precision.

qfloat qfact(const qfloat *,qfloat *);

Factorial

qfloat qrand(void);

Returns a random qfloat.

 

Extended library

 

This library is distributed with the e-mail distribution, together with the source code.

 

Function

Description

void qerf(const qfloat *x,qfloat *y);

Error function integral y=erf(x)

void qerfc(const qfloat *x,qfloat *y);

Complementary error function integral 1-erf(x)

int qcbrt(const qfloat *x,qfloat *y);

Cubic root of x.

void qtanh(const qfloat *x,qfloat *y);

y = atanh(x)

void qsinh(const qfloat *x,qfloat *y);

y = sinh(x)

void qcosh(const qfloat *x,qfloat y);

y = cosh(x)

void qkn(const int,const qfloat *x,qfloat *y);

Modified Bessel function third kind, integer order

void qincbi(const qfloat *a, const qfloat *b, const qfloat *y, const qfloat *result);

Inverse beta integral.

Given y, this function finds x such that:

incbet(a,b,x) == y

void qigami(const qfloat *a,const qfloat *y0,qfloat *answer);

Calculates the inverse of the complemented incomplete gamma integral.

void qfresnl(qfloat *x, qfloat *ss, qfloat *result);

Calculates the Fresnel integral

voi qellpj(qfloat *u, qfloat *m, qfloat *sn, qfloat *cn, qfloat *dn qfloat *result);

Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m), and dn(u|m) of parameter m between 0 and 1, and real  argument u.

These functions are periodic, with quarter-period on the real axis equal to the complete elliptic integral  ellpk(1.0-m).

void qshici(const qfloat *x,qfloat *sinInverse, qfloat *cosInverse);

Calculates the hyperbolic sine and cosine in sinInverse and cosInverse

void qndtri(qfloat *x, qfloat *y);

Calculates the Inverse of the normal distribution.

void qdptri(int k,qfloat *x,qfloat *result);

Inverse Poisson Distribution

Finds the Poisson variable x such that the integral from 0 to x of the Poisson density is equal to the given probability y.

 This is accomplished using the inverse gamma integral function and the relation

    m = igami( k+1, y ).

void qpdtrc(int k,qfloat *m,qfloat *result);

Complemented Poisson distribution.

void qpdtr(int k, qfloat *m, qfloat *y);

Poisson distribution.

Returns the sum of the first k terms of the posisson distribution.

void qnbdtc(int k, int n, qfloat *p, qfloat *y);

Complemented negative binomial distribution.

Returns the sum of the terms k+1 to infinity of the negative binomial distribution. The arguments must be positive, with p ranging from 0 to 1.

void qnbdtr(int k, int n, qfloat *p, qfloat *y);

Negative binomial distribution.

Returns the sum of the terms 0 through k of the negative

binomial distribution.

int qqdtrc(qfloat *a, qfloat *b, qfloat *x, qfloat *result);

Complemented gamma distribution function

Returns the integral from x to infinity of the gamma probability density function. The incomplete gamma integral is used, according to the relation:

y = igamc(b,ax);

int qqdtr(qfloat *a, qfloat *b, qfloat *x, qfloat *result);

Gamma distribution function.

Returns the integral from zero to x of the gamma probability density function.

void qfdtri(int ia, int ib, qfloat *y, qfloat *result);

Inverse of the complemented F distribution.

Finds the F density argument x such that the integral from x to infinity of the F density is equal to the given probability p.

This is accomplished using the inverse beta integral function and the relations:

z = incbi( df2/2, df1/2, p )

x = df2 (1-z) / (df1 z)

void qfdtrc(int ia, int ib, qfloat *a,qfloat *result);

Complemented F distribution.

Returns the area from x to infinity under the F density function (also known as Snedcor's density or the

variance ratio density).

void qchdti(qfloat *df, qfloat *y, qfloat *result);

Inverse of complemented Chi-square distribution.

Finds the Chi-square argument x such that the integral from x to infinity of the Chi-square density is equal to the given cumulative probability y.

void chdtr(qfloat *df, qfloat *x, qfloat *result);

Chi-square distribution.

Returns the area under the left hand tail (from 0 to x) of the Chi square probability density function with v degrees of freedom.

void qbdtri(int k, int n, qfloat *p, qfloat *result);

Inverse binomial distribution.

Finds the event probability p such that the sum of the terms 0 through k of the Binomial probability density is equal to the given cumulative probability y.

void qbdtrc(int k, int n, qfloat *p, qfloat *result);

Complemented binomial distribution.

Returns the sum of the terms k+1 through n of the Binomial probability density.

void qdbtr(int k, int n, qfloat *p, qfloat * result);

Binomial distribution.

Returns the sum of the terms 0 through k of the Binomial probability density.

void qstudt(int k, qfloat *t, qfloat *result);

Student's t distribution

Computes the integral from minus infinity to t of the Student

t distribution with integer k > 0 degrees of freedom.

Relation to incomplete beta integral:

1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )

where

z = k/(k + t**2)

void qellpk(qfloat *x, qfloat *result);

Complete elliptic integral of the first kind.

 

void qei(qfloat *x, qfloat *result);

Exponential integral.

 

Ei(x) = ò et / t dt.

void qigamc(qfloat *a, qfloat *x, qfloat *result);

Complementary incomplete gamma integral.

void qigam(qfloat *a, qfloat *x, qfloat *result);

Incomplete gamma integral.

void qpsi(qfloat *x,qfloat *result);

Psi (digamma) function.

void qsici(qfloat *x, qfloat *si, qfloat *ci);

Evaluates the sine and cosine integrals, returned in si and ci.

void qlgam(qfloat *x,qfloat *result);

Natural logarithm of the gamma function

void qplanck(qfloat *w,qfloat *T, qfloat *y);

Integral of Planck's radiation formula

void qairy(qfloat *x,afloat *ai,qfloat *aip, qfloat *bi,qfloat *bip);

Solution of the differential equation

y"(x) = xy

void qbeta(qfloat *a,qfloat *b,qfloat *result);

This returns:

gamma(a)*gamma(b)

 --------------------------

 gamma(a+b)

void qhy2f1(qfloat *a, qfloat *b, qfloat *x, qfloat *result);

Gauss hypergeometric function.

Returns

1+ sum of k=zero to inf of

a*(a+1)*…(a+k)*b*(b+1)…(b+k)

 ----------------------------------------

c*(c+1)*…(c+k)

multiplied by x to the k+1 power

void qellpe(qfloat *x,qfloat *result);

Complete elliptic integral of the second kind.

void qhyp(qfloat *a, qfloat *b, qfloat *x, qfloat *result);

Confluent hypergeometric function.

void qerf(qfloat *x, qfloat *result);

Error function.

void qerfc(qfloat *x, qfloat *result);

Complementary error function.

void qin(qfloat *n, qfloat *x, qfloat *result);

Modified Bessel function I of non-integer order.

void qine(qfloat *v, qfloat *x, qfloat *result);

Modified Bessel function I of non-integer order exponentially scaled.

void qincb(qfloat *a, qfloat *b, qfloat *x, qfloat *result);

Incomplete Beta integral.

void qjn(qfloat *n, qfloat *x, qfloat *result);

Bessel function of non-integer order.

void qk0(qfloat *x,qfloat *result);

Modified Bessel function K of order zero.

void qspenc(qfloat *x, qfloat *result);

Dilogarithm.

void qndtr(qfloat *x, qfloat *result);

Normal distribution

void qkn(int n, qfloat *x, qfloat *result);

Modified Bessel function of the third kind, integer order

void qyn(qfloat *n, qfloat *x, qfloat *y);

Real Bessel function of second kind, general order.

void qzetac(qfloat *x, qfloat *result);

Riemann zeta function